package 代理学习.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

@SuppressWarnings("all")
public class Test {
    public static void main(String[] args) {
        Customer c = new Customer();
        //使用cglib
        Customer cr = (Customer) Enhancer.create(c.getClass(), new MethodInterceptor() {
            @Override
            public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
                //一样的操作逻辑
                if ("order".equals(method.getName())) {
                    return method.invoke(c, args) + "abc";
                }
                return method.invoke(c, args);
            }
        });
        cr.order("shit");
    }
}
